package com.neusoft.elmboot.controller;

import com.neusoft.elmboot.po.Envelope;
import com.neusoft.elmboot.po.User;
import com.neusoft.elmboot.result.Result;
import com.neusoft.elmboot.service.EnvelopeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 红包
 * Controller
 */
@Slf4j
@RestController
@RequestMapping("/EnvelopeController")
public class EnvelopeController {

    @Autowired
    EnvelopeService envelopeService;

    /**
     * 领取红包
     * @param user
     * @return
     */
    @RequestMapping("/getEnvelopeByUserId")
    public Result getEnvelopeByUserId(User user){
        envelopeService.getEnvelopeByUserId(user);
        log.info("调用接口：获取红包");
        return Result.success();
    }

    /**
     * 根据用户ID列出红包信息
     * @param user
     * @return
     */
    @RequestMapping("/listEnvelopeByUserId")
    public Result<List<Envelope>> listEnvelopeByUserId(User user){
        List<Envelope> list = envelopeService.listEnvelopeByUserId(user.getUserId());
        log.info("调用接口：根据用户ID列出红包信息");
        return Result.success(list);
    }

    /**
     * 根据红包ID列出红包金额
     * @param id
     * @return
     */
    @RequestMapping("/getEnvelopeAmountById")
    public Result<Double> getEnvelopeAmountById(Integer id){
        Double Amount = envelopeService.getEnvelopeAmountById(id);
        log.info("调用接口：根据红包ID列出红包金额");
        return Result.success(Amount);
    }
}
